package com.keai.log;







import com.alibaba.dubbo.config.annotation.Reference;
import com.keai.pojo.LogMessage;
import com.keai.service.LogService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Date;

@Aspect
@Component
public class Log {
    @Reference
    LogService logService;
    @Pointcut("execution(* com.keai.controller.*.*(..))")
    public void pionCut(){};
    @Around("pionCut()")
    public Object around(ProceedingJoinPoint joinPoint){
        try {

            Object method = joinPoint.proceed();

            LogMessage logMessage=new LogMessage();



            String name = joinPoint.getSignature().getName();
            logMessage.setDate(new Date());
            logMessage.setMethod(name);
            String className = joinPoint.getTarget().getClass().getName();
            logMessage.setClassname(className);




            if (!(logMessage.getMethod().contains("loginSuccess")||logMessage.getMethod().contains("findPage")||logMessage.getMethod().contains("findUsername")||logMessage.getMethod().contains("findMenu"))){

                logService.addLog(logMessage);
            }

            return method;
        } catch (Throwable throwable) {
            throwable.printStackTrace();

            return null;

        }
    }
}
